# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=cryptol
pkgver=2.13.0
pkgrel=122
pkgdesc="The Language of Cryptography"
url="https://www.cryptol.net"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'z3' 'haskell-arithmoi' 'haskell-async' 'haskell-base-compat' 'haskell-bv-sized'
         'haskell-cryptohash-sha1' 'haskell-extra' 'haskell-gitrev'
         'haskell-graphscc' 'haskell-heredoc' 'haskell-libbf' 'haskell-memotrie'
         'haskell-monad-control' 'haskell-monadlib' 'haskell-optparse-applicative'
         'haskell-parameterized-utils' 'haskell-panic' 'haskell-prettyprinter' 'haskell-sbv'
         'haskell-simple-smt' 'haskell-strict' 'haskell-temporary' 'haskell-tf-random'
         'haskell-transformers-base' 'haskell-what4' 'haskell-ansi-terminal' 'haskell-blaze-html')
makedepends=('ghc' 'uusi' 'alex' 'happy')
source=(https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('a4979ca1a11fbbfb5f2f4741fa15ece50c76c84a194eea44844c4e88b4a371796e245be3b061429966db0f4013ca799b6096e152db7166c9d5833db654dc2121')

prepare() {
    cd $pkgname-$pkgver
    uusi -u what4 cryptol.cabal
}

build() {
    cd $pkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-static -f-relocatable --ghc-option='-pie'
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $pkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $pkgname-$pkgver

    install -D -m744 register.sh   "${pkgdir}/usr/share/haskell/register/${pkgname}.sh"
    install -D -m744 unregister.sh "${pkgdir}/usr/share/haskell/unregister/${pkgname}.sh"
    runhaskell Setup copy --destdir="${pkgdir}"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
